package com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hyphenate.easeui.utils.Preferences;
import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.PushSContract;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.PushSettingsPresenter;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/23 14:48
 * 功能描述： 推送界面
 * 联系方式：1037438704@qq.com
 */
public class PushSettingsActivity extends BaseActivity implements PushSContract {
    @BindView(R.id.image_left_finish)
    ImageView imageleftFinish;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.text_right)
    TextView textRight;
    @BindView(R.id.image_boole_1)
    ImageView imageBoole_1;
    @BindView(R.id.image_booleal_2)
    ImageView imageBooleal_2;
    private int boolean1 = 2;
    private int boolean2 = 2;
    private PushSettingsPresenter presenter;
    private String tuisong;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_push_settings;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        // 私聊 推送设置
        tuisong = Preferences.getInstance().getString(this, "user", "tuisong");
        if (!TextUtils.isEmpty(tuisong)) {
            boolean1 = Integer.valueOf(tuisong);
        }
        if (boolean1 == 2) {
            imageBoole_1.setImageResource(R.mipmap.icon_voice_broadcast_declaration);
        } else {
            imageBoole_1.setImageResource(R.mipmap.icon_voice_true);
        }
        imageleftFinish.setVisibility(View.VISIBLE);
        textCenter.setText("推送设置");
        presenter = new PushSettingsPresenter(this, this);
        presenter.setPush1(token, "", "1");
//        私聊消息 1是 2否
//        有新的约会 1是 2否
//        有女士通过了我的查看请求
    }

    @OnClick({R.id.image_left_finish, R.id.image_booleal_2, R.id.image_boole_1})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left_finish:
                finish();
                break;
            case R.id.image_boole_1:
                if (boolean1 == 2) {
                    boolean1 = 1;
                    imageBoole_1.setImageResource(R.mipmap.icon_voice_true);
                } else {
                    boolean1 = 2;
                    imageBoole_1.setImageResource(R.mipmap.icon_voice_broadcast_declaration);
                }
                Preferences.getInstance().set(this, "user", "tuisong", boolean1 + "");
//                presenter.setPush1(token, boolean1 + "", "2");
                break;
            case R.id.image_booleal_2:
                if (boolean2 == 2) {
                    boolean2 = 1;
                    imageBooleal_2.setImageResource(R.mipmap.icon_voice_true);
                } else {
                    boolean2 = 2;
                    imageBooleal_2.setImageResource(R.mipmap.icon_voice_broadcast_declaration);
                }
                presenter.setPush1(token, boolean2 + "", "2");
                break;
            default:
        }
    }

    @Override
    public void Success(Map<String, String> data) {
        String new_yue = data.get("new_yue");
        if (!TextUtils.isEmpty(new_yue)) {
            boolean2 = Integer.valueOf(new_yue);
        }
        //  1是 2否
        if (new_yue.equals("1")) {
            imageBooleal_2.setImageResource(R.mipmap.icon_voice_true);
        } else {
            imageBooleal_2.setImageResource(R.mipmap.icon_voice_broadcast_declaration);
        }
    }
}